New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

base-compose

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

base-compose

Selectively merge values from one or more generators onto the current application instance.

  • 0.1.5
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

base-compose NPM version NPM downloads Build Status

Selectively merge values from one or more generators onto the current application instance.

Install

Install with npm:

$ npm install base-compose --save

This plugin requires the base-generators to be registered first. If not already registered, you can do so now by following these instructions.

Usage

var compose = require('base-compose');
var Base = require('base');
var app = new Base();

// register the "compose" plugin
app.use(compose());

API

Heads up!

Some of the methods exposed on .compose expect for app to be an instance of templates, or for specific plugins to be registered first.

You don't need to register all of the plugins prescribed below, just use the plugins you need with the methods you need. base-compose will give you detailed error messages when something is missing.

More information is provided in the methods documentation below.

.compose

Setup a composition by passing in an array of generators to compose elements. If a generator cannot be found, an error will be thrown.

Params

  • names {String|Array}: One or more generator names.
  • returns {Object}: Returns an instance of Compose

Example

app.compose(['a', 'b', 'c'])
  .data()
  .options()
  .helpers()
  .views();

.compose.options

Merge the options from each generator into the app options. This method requires using the [base-option][base-option] plugin.

Params

  • key {String}: Optionally pass the name of a property to merge from the options object. Dot-notation may be used for nested properties.
  • returns {Object}: Returns the Compose instance for chaining

Example

a.option({foo: 'a'});
b.option({foo: 'b'});
c.option({foo: 'c'});

app.compose(['a', 'b', 'c'])
  .options();

console.log(app.options);
//=> {foo: 'c'}

.compose.data

Merge the cache.data object from each generator onto the app.cache.data object. This method requires the .data() method from templates.

Params

  • key {String}: Optionally pass a key to merge from the data object.
  • returns {Object}: Returns the Compose instance for chaining

Example

a.data({foo: 'a'});
b.data({foo: 'b'});
c.data({foo: 'c'});

app.compose(['a', 'b', 'c'])
  .data();

console.log(app.cache.data);
//=> {foo: 'c'}

.compose.engines

Merge the engines from each generator into the app engines. This method requires the .engine() methods from templates.

  • returns {Object}: Returns the Compose instance for chaining

Example

app.compose(['a', 'b', 'c'])
  .engines();

.compose.helpers

Merge the helpers from each generator into app.helpers. Requires the .helper method from templates.

  • returns {Object}: Returns the Compose instance for chaining

Example

app.compose(['a', 'b', 'c'])
  .helpers();

.compose.pipeline

Merge the pipeline plugins from each generator onto app.plugins. Requires the base-pipeline plugin to be registered.

  • returns {Object}: Returns the Compose instance for chaining

Example

app.compose(['a', 'b', 'c'])
  .pipeline();

.compose.tasks

Copy the specified tasks and task-dependencies from each generator onto app.tasks. Requires using the base-task plugin to be registered.

Params

  • tasks {String|Array}: One or more task names (optional)
  • returns {Object}: Returns the Compose instance for chaining

Example

app.compose(['a', 'b', 'c'])
  .tasks(['foo', 'bar', 'default']);

// or to copy all tasks
app.compose(['a', 'b', 'c'])
  .tasks();

.compose.views

Copy view collections and views from each generator onto app. Expects app to be an instance of templates.

Params

  • names {Array|String}: (optional) Names of one or more collections to copy. If undefined all collections will be copied.
  • filter {Function}: Optionally pass a filter function to filter views copied from each collection. The filter function exposes key, view and collection as arguments. If used, the function must return true to copy a view.
  • returns {Object}: Returns the Compose instance for chaining

Example

app.compose(['a', 'b', 'c'])
  .views();

.compose.iterator

Returns an iterator function for iterating over an array of generators. The iterator takes a fn that exposes the current generator being iterated over (generator) and the app passed into the original function as arguments. No binding is done within the iterator so the function passed in can be safely bound.

Params

  • names {Array}: Names of generators to iterate over (optional).
  • iteratorFn {Function}: Function to invoke for each generator in generators. Exposes app and generator as arguments.
  • returns {Object}: Returns the Compose instance for chaining

Example

app.compose(['a', 'b', 'c'])
  .iterator(function(generator, app) {
    // do work
    app.data(generator.cache.data);
  });

// optionally pass an array of additional generator names as the
// first argument. If generator names are defined on `iterator`,
// any names passed to `.compose()` will be ignored.
app.compose(['a', 'b', 'c'])
  .iterator(['d', 'e', 'f'], function(generator, app) {
    // do stuff to `generator` and `app`
  });

base-generators

Follow these instructions to install and register the base-generators plugin before registering base-compose.

Install base-generators

$ npm install base-generators --save

Register base-generators

var generators = require('base-generators');
var compose = require('base-compose');
var Base = require('base');
var app = new Base();

// register plugins
app.use(generators());
app.use(compose());

You might also be interested in these projects:

  • assemble: Assemble is a powerful, extendable and easy to use static site generator for node.js. Used… more | homepage
  • base: base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… more | homepage
  • generate: Fast, composable, highly extendable project generator with a user-friendly and expressive API. | homepage
  • verb: Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… more | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

Generate readme and API documentation with verb:

$ npm install verb && npm run docs

Or, if verb is installed globally:

$ verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Brian Woodward

License

Copyright © 2016, Brian Woodward. Released under the MIT license.


This file was generated by verb, v0.9.0, on April 21, 2016.

Keywords

FAQs

Package last updated on 07 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc